package com.yanlight.app.service.impl;

import com.yanlight.app.dal.dao.PaycodeDAO;
import com.yanlight.app.dal.entity.PayCode;
import com.yanlight.app.service.PayCodeService;
import com.yanlight.util.DateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PayCodeServiceImpl implements PayCodeService {

    @Autowired
    PaycodeDAO paycodeDAO;

    @Override
    public PayCode queryInfo(String value) {
        PayCode byValue = paycodeDAO.findByValue(value);
        return byValue;
    }


    @Override
    public PayCode update(PayCode payCode) {
        //此时为绑定公司，设置绑定时间
        if (payCode.getCompanyId() != null) {
            payCode.setBindTime(DateTimeUtil.getNowTime());
        }
        int update = paycodeDAO.update(payCode);
        if (update > 0) {
            Integer id = payCode.getId();
            PayCode byId = paycodeDAO.findById(id);
            return byId;
        }
        return null;
    }
}
